<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <%@ include file="/WEB-INF/views/include/head.jsp"%> 
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <link rel="stylesheet" href="${ctxStatic}/css/list.css">
        <script>
           $(function(){
           
               $("#shopCountry,#styleCodes,#shopCity").select2();
           });
           //城市联动
           function cityFun(t,id){
               var code=$(t).find("option:selected").attr("data-value");
               var param={"code":code};
               $.post("${ctx}/sys/myshop/city",param,function(result){
                   var html="<option value=''><spring:message code='shop_saveregion'/></option>";
                   $.each(result,function(i,e){
                       html+="<option value='"+e.itemCode+"-"+e.itemValue+"'>"+e.itemName+"</option>";
                   });
                   $("#"+id).html(html);
                   $("#"+id).select2();
               },'json');
           }
           //保存
           var saveForm={
                t:null,
                save:function(t){
                    $(t).attr("disabled",true);
                    this.t=t;
                    $("#inputForm").validate({
                        submitHandler: function() {
                            var params = $("#inputForm").serialize();
                            $.post("${ctx}/sys/myshop/save",params,function(result){
                                tipParent(result.message);
                                if(result.statusCode==STATUSCODEOK){
                                    window.location.href="${ctx}/sys/myshop/list";
                                }else{
                                    $(saveForm.t).attr("disabled",false);
                                }
                            },'json'); 
                        },
                        rules: {
                            shopName: {remote: "${ctx}/sys/myshop/checkShopName?oldShopName=" + encodeURIComponent("${shop.shopName}")},
                            },
                        messages: {
                            shopName: {remote: '<spring:message code="shop_shopName_exist"/>'},
                        },
                        fail: function(element,e) {  
                            $(saveForm.t).attr("disabled",false);
                        }
                    }); 
                $("#inputForm").submit(); 
                }
            }
        </script>
    </head>
    <body>
        <div class="myshop">
            <p class="myshoptop"><spring:message code="shop_myShop"/></p>
        </div>
        <c:set value="<%=ResourcesUtil.getConfig(\"shop_country\")%>" var="shopCountry" />
        <c:set value="<%=ResourcesUtil.getConfig(\"shop_styleCategory\")%>" var="shopStyleCategory" />
        <form id="inputForm" method="post">
            <input type="hidden"  name="ognizationId"  value="-1">
            <input type="hidden"  name="id"  value="${shop.id }">
            <input type="hidden"  name="version"  value="${shop.version} ">
            <div class="myshop_middle" style="padding: 10px 35px 0 35px;">
                <div class="data clearfix">
                    <div class="ch fl haveToBox">
                        <!-- 店铺名称 -->
                        <p class="data_id"><spring:message code="shop_shopName"/></p>
                        <input type="text" name="shopName" data-msg-required="<spring:message code="shop_saveShopName"/>" data-rule-required="true" maxlength="20" value="${shop.shopName}" class="form-control" >
                        <input type="hidden"  class="form-control" name="oldShopName" value="${shop.shopName }">
                        <p class="haveTo">*</p>
                    </div>
                    <div class="ch fr haveToBox">
                        <!-- 联系人 -->
                        <p class="data_id"><spring:message code="shop_contacts"/></p>
                        <input type="text" name="contactPerson" data-msg-required="<spring:message code="shop_saveShopContactPerson"/>" data-rule-required="true" maxlength="20" value="${shop.contactPerson }" class="form-control">
                        <p class="haveTo">*</p>
                    </div>
                </div>
                <div class="data clearfix">
                    <div class="ch fl">
                        <div class=" fl haveToBox">
                        <!-- 所在国家 -->
                            <p class="data_id"><spring:message code="shop_hostCountry"/></p>
                            <select class="country" id="shopCountry" data-msg-required="<spring:message code="shop_saveCountry"/>" data-rule-required="true"  name="shopCountry" onchange="cityFun(this,'shopCity')">
                                <option value=""><spring:message code="shop_saveCountry"/></option>
                                <c:forEach items="${fns:getDictList(shopCountry)}"   var="country">
                                    <option data-value="${country.itemValue}" <c:if test="${fn:split(shop.shopCountry, '-')[1] eq country.itemValue}">selected="selected"</c:if> value="${country.itemCode}-${country.itemValue}">${country.itemName}</option>
                                </c:forEach>
                            </select>
                            <p class="haveTo">*</p>
                        </div>
                        <div class=" fr haveToBox">
                        <!-- 所在地区 -->
                            <p class="data_id"><spring:message code="shop_region"/></p>
                            <select class="country" id="shopCity" data-rule-required="true" data-msg-required="<spring:message code="shop_saveregion"/>" name="shopCity" >
                                 <option value=""><spring:message code="shop_saveregion"/></option>
                                 <c:forEach items="${fns:getDictList(fn:split(shop.shopCountry, '-')[1])}" var="city">
                                    <option 
                                        <c:if test="${fn:split(shop.shopCity, '-')[1] eq city.itemValue}">selected="selected"</c:if>  value="${city.itemCode}-${city.itemValue}">
                                        ${city.itemName}
                                    </option>
                                 </c:forEach>
                            </select>
                              <p class="haveTo">*</p>
                         </div>
                    </div>
                    <div class="ch fr">
                    <!-- 联系电话 -->
                        <p class="data_id"><spring:message code="shop_contactNumber"/></p>
                        <input type="text" name="contactPhone" maxlength="11"  value="${shop.contactPhone }" class="form-control" data-rule-banjiao="true" data-msg-banjiao="<spring:message code="shop_pleaseInput_banjiao"/>" >
                    </div>
                </div>
                <div class="data clearfix">
                    <div class="ch fl">
                    <!-- 店铺地址 -->
                        <p class="data_id"><spring:message code="shop_address"/></p>
                        <textarea class="shopint" style="height:70px" name="shopAddress"  maxlength="50"  >${shop.shopAddress }</textarea>
                    </div>
                    <div class="ch fr">
                        <div class="ch data clearfix">
                        <!-- 联系传真 -->
                            <p class="data_id"><spring:message code="shop_fax"/></p>
                            <input type="text" name="contactFax" value="${shop.contactFax }"  maxlength="20"  class="form-control" data-rule-banjiao="true" data-msg-banjiao="<spring:message code="shop_pleaseInput_banjiao"/>" >
                        </div>
                        <div class="ch clearfix haveToBox">
                            <!-- 联系邮箱 -->
                            <p class="data_id"><spring:message code="shop_mailbox"/></p>
                            <input type="text" name="contactEmail" data-rule-required="true" data-msg-required="<spring:message code="shop_saveEmail"/>" data-rule-required="true" maxlength="50"  value="${shop.contactEmail }" class="form-control" data-rule-email="true" data-msg-email="<spring:message code="MyCustomer_PlsInputEmail"/>">
                              <p class="haveTo">*</p>
                        </div>
                    </div>
                </div>
                <div class="data clearfix">
                    <div class="ch fl clearfix">
                        <div class="ch data clearfix">
                            <!-- 店铺简介 -->
                            <p class="data_id"><spring:message code="shop_shopProfile"/></p>
                            <textarea class="shopint" style="height:118px;" name="shopDiscribe"  maxlength="200"  >${shop.shopDiscribe }</textarea>
                        </div>
                        <div class="ch clearfix haveToBox">
                        <!-- 开户银行 -->
                            <p class="data_id"><spring:message code="shop_bankAccount"/></p>
                            <input type="text" name="bankName" data-rule-required="true" data-msg-required="<spring:message code="shop_bankAccount"/>" maxlength="50"  value="${shop.bankName }" class="form-control" >
                        	<p class="haveTo">*</p>
                        </div>
                    </div>
                    <div class="ch fr clearfix">
                        <div class="ch_top clearfix haveToBox">
                            <!-- 店铺标识 -->
                            <p class="data_id"><spring:message code="shop_shopLogo"/></p>
                            <div class="square" style="width:160px;">
                                <input type="hidden" id="nameImage" data-msg-required="<spring:message code="shop_saveShopLogo"/>" data-rule-required="true" name="shopLogo" value="${shop.shopLogo}" htmlEscape="false" maxlength="255" class="input-xlarge"/> 
                                <sys:ckfinder input="nameImage" type="images" uploadPath="/shopLogo" selectMultiple="false" maxWidth="120" maxHeight="120"/>
                            </div>
                            <p class="haveTo">*</p>
                        </div>
                    </div>
                </div>
                <div class="data clearfix">
                    <div class="ch fl clearfix haveToBox">
                    <!-- 银行账号 -->
                        <p class="data_id"><spring:message code="shop_bankAccountNO"/></p>
                        <input type="text" data-msg-required="<spring:message code="shop_bankAccountNO"/>" data-rule-required="true" class="form-control" name="bankAccountNo"  data-rule-nonnegativeInteger="true"  data-msg-nonnegativeInteger="<spring:message code="shop_saveBankAccountNO"/>" maxlength="20"  value="${shop.bankAccountNo }" >
                    	<p class="haveTo">*</p>
                    </div>
                    <div class="ch_bottom ch fr clearfix haveToBox">
                    <!-- 经营款式 -->
                        <p class="data_id"><spring:message code="shop_managementStyle"/></p>
                        <select class="sex mult" id="styleCodes" multiple="multiple" name="styleCodes" data-rule-required="true" data-msg-required="<spring:message code="shop_plsChooseAGategory"/>">
                            <%-- <option value=""><spring:message code="myMaterial_pleaseChoosed"/></option> --%>
                            <c:forEach items="${fns:getDictList(shopStyleCategory)}"   var="style">
                                 <option  value="${style.itemCode}-${style.itemValue}"
                                  <c:forEach items="${shopStyleSelectList}" var="shopStyle" >
                                    <c:if test="${fn:split(shopStyle.itemId,'-')[1] eq style.itemValue}">selected="selected"</c:if>
                                   </c:forEach>
                                  > 
                                    ${style.itemName}
                                </option> 
                            </c:forEach>
                        </select>
                    	<p class="haveTo">*</p>
                    </div>
                </div>
            </div>
            <div class="Pre-box">
                <!--保存 -->
                <shiro:hasPermission name="sys:myshop:edit">
                <div class="Pre"  onclick="saveForm.save(this)"><spring:message code="common_save"/></div>
                 </shiro:hasPermission>
            </div>
        </form>
        <script>
            var listH = $(':root').css('height')
            $(window.parent.$("#mainFrame").css('height',listH));
        </script>
    </body>
</html>